package DailyPractice;

import com.sun.org.apache.xpath.internal.objects.XNumber;

import java.util.Scanner;

public class MethodText {
    // 求两个数的最大值
    public static int max2(int num1, int num2) {
        return num1 > num2 ? num1 : num2;
    }

    // 求三个数的最大值
    public static int max3(int num1, int num2, int num3) {
        int temp = max2(num1, num2);
        return max2(temp, num3);
    }

    //输出最大值
    public static void PrintMaxNumber() {
        // 获取用户输入
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入第一个整数： ");
        int a = scanner.nextInt();
        System.out.print("请输入第二个整数： ");
        int b = scanner.nextInt();
        System.out.print("请输入第三个整数： ");
        int c = scanner.nextInt();

        // 输出最大值
        System.out.println("三个数中的最大值是：" + max3(a, b, c));
    }

    //阶乘
    public static void FactNumber() {
        //获取用户输入
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入n的值：");
        int n = scanner.nextInt();
        int number = 1;

        //求阶乘
        for (int i = 1; i <= n; i++) {
            number *= i;
        }
        System.out.println(n + "的阶乘为" + number);
    }

    //阶乘的和
    public static void FactNumberSum() {
        //获取用户输入
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入n的值：");
        int n = scanner.nextInt();
        int sum = 0;

        for (int i = 1; i <= n; i++) {
            int number = 1;
            //求1、2、3……的阶乘
            for (int j = 1; j <= i; j++) {
                number *= j;

            }
            sum += number;//阶乘求和
        }
        System.out.println(n + "的阶乘和为" + sum);
    }

    //斐波那契数列
    public static int fibonacci(int n) {
        if (n <= 1) {
            return n;
        } else {
            int a = 0;
            int b = 1;
            for (int i = 2; i <= n; i++) {
                int c = a + b;
                a = b;
                b = c;
            }
            return b;
        }
    }

    //求两个整数和的方法
    public static int Sum(int a, int b) {
        return a + b;
    }

    //求三个小数和的方法（方法重载）
    public static double Sum(double a, double b, double c) {
        return a + b + c;
    }

    //求两个整型的最大值方法
    public static int MaxValue(int num1, int num2) {
        return num1 > num2 ? num1 : num2;
    }

    //求三个小数最大值的方法（方法重载）
    public static double Maxvalue(double num1, double num2, double num3) {
        double i = num1 > num2 ? num1 : num2;
        return i > num3 ? i : num3;
    }

    public static void main(String[] args) {
        //PrintMaxNumber();//求最大值
        //FactNumber();//求n的阶乘
        //FactNumberSum();//求n的阶乘和
        /*int n = 10;
        System.out.println("斐波那契数列的第 " + n + " 项为：" + fibonacci(n));//求斐波那契数列第n项*/
        //System.out.println(Sum(3,5));
        //System.out.println(Sum(7.3,9.6,4.5));
        System.out.println(MaxValue(10, 20));
        System.out.println(Maxvalue(25.3, 69.4, 24.6));

    }
}
